package com.bjpowernode.crm.workbench.web.controller;

import com.bjpowernode.crm.settings.domain.DictionaryValue;
import com.bjpowernode.crm.settings.domain.User;
import com.bjpowernode.crm.settings.service.DicService;
import com.bjpowernode.crm.settings.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.ResourceBundle;

/**
 * ClassName:TransactionController
 * package:com.bjpowernode.crm.workbench.web.controller
 * Description:
 *
 * @date: 2022-06-14 20:19
 * @author：lin
 */
//href="workbench/transaction/toIndex.do"
@Controller
@RequestMapping("/workbench/transaction")
public class TransactionController {

    @Autowired
    private UserService userService;

    @Autowired
    private DicService dicService;


    @RequestMapping("/toIndex.do")
    public String toIndex(){
        return "/workbench/transaction/index";

    }

    //onclick="window.location.href='workbench/transaction/toSave.do
    //跳转交易保存页面
    @RequestMapping("/toSave.do")
    public String toSave(Model model){
       List<User> userList= userService.getUser();
       List<DictionaryValue> stageList = dicService.searchDicValue("stage");
       List<DictionaryValue> transactionList = dicService.searchDicValue("transactionType");
       List<DictionaryValue> sourceList = dicService.searchDicValue("source");
       model.addAttribute("userList",userList);
       model.addAttribute("stageList",stageList);
       model.addAttribute("transactionList",transactionList);
       model.addAttribute("sourceList",sourceList);

        return "/workbench/transaction/save";

    }

    //url:"workbench/transaction/stageValue.do",               //请求路径
    //获取阶段的value 即可能性
    @RequestMapping("/stageValue.do")
    @ResponseBody
    public String stageValue(String stageValue ){
       //获取properties 文件的 key value possibility.properties
       ResourceBundle bundle =ResourceBundle.getBundle("properties/possibility");
       String value=bundle.getString(stageValue);
       return value;

    }

}
